<?php
	/**
	* @File name:	cache.php
	* @Desription:	description
	* @Author:	 	jinxin<jx@178.com>   
	* @Date:	 	Tue Jun 14 14:35:27 CST 2011
	* @Copyright 	Copytright (c) 2008-2011 178.COM Co., Ltd.
	* @version	 	$Id $
	*/
	
/**
	$_SERVER['config']['mem'] = array(
		array(
			'host'=>'127.0.0.1',
			'port'=>'11211'
		),
	);
**/
	
	class cache
	{
		public static $getInstence;
		public static $class = __CLASS__;
		public $cacheSever;
		public function __construct(){
			if (is_array($_SERVER['config']['mem'])){
				$this->cacheSever = new Memcache();
				$this->connect($_SERVER['config']['mem']);
			}
		}
		
		public function __destruct(){}
		
		public function connect($conf){
			foreach ($conf as $serverInfo){
				$this->cacheSever->addServer($serverInfo['host'],$serverInfo['port']);
			}
		}
		
		public static function getInstence(){
			if (!self::$getInstence){
				self::$getInstence = new self::$class();
			}
			return self::$getInstence;
		}
		
		public function add($key,$value,$left_time=60){
			$this->cacheSever->add($key,$value,0,$left_time);
		}
		
		public function remove($key){
			$this->cacheSever->delete($key);
		}
		public function set($key,$value,$flag=0,$left_time=60){
			$this->cacheSever->set($key,$value,0,$left_time);
		}
		
		public function load($key){
			$ret = $this->cacheSever->get($key);
			return $ret;
		}
	}
	
/**
	$a = 'cc';
	cache::getInstence()->set('my_memcache_key_123',22);
	cache::getInstence()->set('my_memcache_key',1111);
	cache::getInstence()->remove('my_memcache_key');
	echo cache::getInstence()->load('my_memcache_key_1');
**/